<?php

namespace App\Console\Commands;

use App\Models\STeacherInfo;
use App\Models\STeaScheduleInfo;
use Carbon\Carbon;
use Illuminate\Console\Command;

class MakeTeacherNextWeekSchedule extends Command {
	/**
	 * The name and signature of the console command.
	 *
	 * @var string
	 */
	protected $signature = 'command:MakeTeacherNextWeekSchedule';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = '每周生成下下周的老师课表安排';

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct() {
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function handle() {
		//每周生成下下周的老师课表安排
		//1,获取所有老师
		//2，生成课表
		$teachers = STeacherInfo::getAllTeacher();

		$update = [];
		$thisWeek = Carbon::now()->addWeeks(2)->startOfWeek();
		for ($i = 0; $i < 8; $i++) {

			$date = $thisWeek->addDay()->toDateString();
			$update[] = [
				'date_time' => $date,
			];
		}

		foreach ($teachers as $tea) {
			// $date = [];
			$time = now();
			foreach ($update as $value) {

				$value['teacher_id'] = $tea->id;
				// $value['created_at'] = $time;
				// $value['updated_at'] = $time;
				// $date[] = $value;
				STeaScheduleInfo::firstOrCreate($value);

			}

			// STeaScheduleInfo::firstOrCreate($date);
		}
	}
}
